#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n;
    cin>>n;
    vector<int> v(n+1);
    int l=1,r=n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    sort(v.begin()+1,v.end());
    while(l+1<=r&&v[l]+v[l+1]<=v[r])
    {
        l++;
    }
    int ans=l-1;
    while(l!=1)
    {
        l--;
        while(l+1<=r&&v[l]+v[l+1]<=v[r])
        {
            r--;
        }
        ans=min(ans,l-1+n-r);
    }
    cout<<ans<<endl;
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}